home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / WASTE Object Handlers 1.2.6.sit / WASTE Object Handlers 1.2.6 / Other Source / SendFinderOpen.c < prev    next >
Text File  |  1997-07-21  |  4KB  |  161 lines

  1. // File Object Handler Utilities for the WASTE Text Engine
  2. // Part of the WASTE Object Handler Library by Michael Kamprath, kamprath@kagi.com
  3. // maintenance by John C. Daub, hsoi@eden.com
  4. //
  5. // v1.2 28 March 1996,  Cleaned up the file with precompiler directives, removing potential
  6. //                        warning messages
  7.  
  8. #ifndef __ALIASES__
  9. #include <Aliases.h>
  10. #endif
  11.  
  12. #ifndef __APPLEEVENTS__
  13. #include <AppleEvents.h>
  14. #endif
  15.  
  16. #include "SendFinderOpen.h"
  17.  
  18. #define kFinderSig            'FNDR'
  19. #define kAEFinderEvents        'FNDR'
  20. #define kSystemType            'MACS'
  21.  
  22. #define    kAEOpenSelection    'sope'
  23. #define keySelection        'fsel'
  24.  
  25. #ifndef true
  26. #define true 1
  27. #endif
  28.  
  29. #ifndef false
  30. #define false 0
  31. #endif
  32.  
  33.  
  34. OSErr SendFinderOpenAE(FSSpec *theDoc)
  35. {
  36. AppleEvent            aeEvent;
  37. AEDesc                myAddressDesc;
  38. AEDesc                aeDirDesc;
  39. AEDesc                listElem;
  40. AEDescList            fileList;
  41. FSSpec                dirSpec;
  42. AliasHandle            dirAlias;
  43. AliasHandle            fileAlias;
  44. ProcessSerialNumber    process;
  45. OSErr                myErr;
  46. OSType            FndrType = 'MACS';
  47.     
  48.     /*
  49.      * Get the psn of the Finder and create the target address for the AE
  50.      */
  51.     
  52.     if ( FindAProcess( kFinderSig, kSystemType, &process) )
  53.         return( procNotFound );
  54.  
  55.     myErr = AECreateDesc( typeProcessSerialNumber, (Ptr)&process, 
  56.                             sizeof(process), &myAddressDesc);
  57.     if (myErr) return(myErr);
  58.     
  59.     /*
  60.      * Create an empty Apple Event
  61.      */
  62.     
  63.     myErr = AECreateAppleEvent( kAEFinderEvents, kAEOpenSelection, &myAddressDesc,
  64.                                 kAutoGenerateReturnID, kAnyTransactionID, &aeEvent);
  65.     
  66.     if (myErr) return(myErr);
  67.     
  68.     /*
  69.      * Make and FSSpec for the parent folder and an alias of the file.
  70.      */
  71.     
  72.     FSMakeFSSpec( theDoc->vRefNum, theDoc->parID, 0L, &dirSpec);
  73.     NewAlias( nil, &dirSpec, &dirAlias);
  74.     NewAlias( nil, theDoc, &fileAlias);
  75.     
  76.     
  77.     /*
  78.      * Create the File list.
  79.      *
  80.      */
  81.     
  82.     HLockHi( (Handle)dirAlias);
  83.     AECreateDesc( typeAlias, (Ptr)*dirAlias, GetHandleSize( (Handle)dirAlias), &aeDirDesc);
  84.     HUnlock( (Handle)dirAlias);
  85.     DisposeHandle( (Handle)dirAlias);
  86.     
  87.     if ( (myErr=AEPutParamDesc(&aeEvent, keyDirectObject, &aeDirDesc)) == noErr )
  88.     {
  89.         AEDisposeDesc( &aeDirDesc );
  90.         
  91.         AECreateList(nil, 0, false, &fileList);
  92.         HLockHi( (Handle)fileAlias);
  93.         myErr = AECreateDesc( typeAlias, (Ptr)*fileAlias, 
  94.                                     GetHandleSize( (Handle)fileAlias), &listElem);
  95.         HUnlock( (Handle)fileAlias);
  96.  
  97.         DisposeHandle( (Handle)fileAlias);
  98.     
  99.         myErr = AEPutDesc( &fileList, 0L, &listElem);
  100.         
  101.         if (myErr) return(myErr);
  102.         
  103.     }
  104.     if (myErr) return(myErr);
  105.     
  106.     AEDisposeDesc(&listElem);
  107.     
  108.     myErr = AEPutParamDesc(&aeEvent, keySelection, &fileList);
  109.     if (myErr) return(myErr);
  110.  
  111.     myErr = AEDisposeDesc( &fileList);
  112.     if (myErr) return(myErr);
  113.     
  114.     myErr = AESend( &aeEvent, 0L, kAENoReply+kAEAlwaysInteract+kAECanSwitchLayer,
  115.                     kAENormalPriority, kAEDefaultTimeout, 0L, 0L);¥
  116.                 
  117.     AEDisposeDesc(&aeEvent);
  118.     
  119.     return(myErr);
  120. }
  121.  
  122. /*
  123.  * Search though the current process list to find the given application. 
  124.  *
  125.  */
  126.  
  127. OSErr FindAProcess( OSType typeToFind, OSType creatorToFind, ProcessSerialNumberPtr processSN)
  128. {
  129. ProcessInfoRec            tempInfo;
  130. FSSpec                    procSpec;
  131. Str31                    processName;
  132. OSErr                    myErr = noErr;
  133.  
  134.     /*
  135.      * Start at begining of process list
  136.      */
  137.     
  138.     processSN->lowLongOfPSN = kNoProcess;
  139.     processSN->highLongOfPSN = kNoProcess;
  140.     
  141.     /*
  142.      * Init the process information record.
  143.      *
  144.      */
  145.     
  146.     tempInfo.processInfoLength = sizeof(ProcessInfoRec);
  147.     tempInfo.processName = (StringPtr)&processName;
  148.     tempInfo.processAppSpec = &procSpec;
  149.     
  150.     while ( (tempInfo.processSignature != creatorToFind || tempInfo.processType != typeToFind)
  151.                 || myErr != noErr)
  152.     {
  153.         myErr = GetNextProcess(processSN);
  154.         if (myErr == noErr)
  155.             GetProcessInformation( processSN, &tempInfo);
  156.     }
  157.         
  158.     return(myErr);
  159. }
  160.  
  161.